package com.hz.springboot02.service.impl;

import com.hz.springboot02.mapper.UserMapper;
import com.hz.springboot02.pojo.User;
import com.hz.springboot02.service.UserService;
import com.hz.springboot02.utils.MessageJson;
import com.hz.springboot02.utils.ResultLayUi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName SmbmsUserServiceImpl
 * @Description 用户业务逻辑实现
 * @Author Administrator
 * @Date 2024/11/18 14:37
 */
@Service
public class UserServiceImpl implements UserService {
    @Resource
    private  UserMapper userMapper ;

    @Override
    public User login(String userName, String userPassword) {
        return userMapper.loginUser(userName,userPassword);
    }

    @Override
    public ResultLayUi listPage(Integer page, Integer limit, String userName, String roleName, String address, String beginDate, String endDate) {
        //偏移量 =（当前页-1）*每页固定条数
        int pyl = (page-1)*limit;
        List<User> userList = userMapper.listPage(pyl,limit,userName,roleName,address,beginDate,endDate);

        return ResultLayUi.success(userMapper.sumNo(userName,roleName,address,beginDate,endDate),userList);
    }

    @Override
    public MessageJson addOrEditUser(User user) {
        return MessageJson.successOrError(user.getId()!=null?userMapper.edit(user):userMapper.insert(user));
    }

    @Override
    public User selectById(Integer id) {
        return userMapper.selectById(id);
    }

    @Override
    public MessageJson delById(Integer id) {
        return userMapper.delById(id)>0?MessageJson.success():MessageJson.error();
    }

    @Override
    public MessageJson delIds(List<Integer> ids) {
        userMapper.delIds(ids);
        return (ids != null && ids.size() > 0)? MessageJson.success(): MessageJson.error();
    }

}
